home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / aga.asm < prev    next >
Assembly Source File  |  1999-03-21  |  15KB  |  758 lines

  1. ; AGA
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.1
  6.  
  7.     MACHINE    68020
  8.  
  9.         INCDIR    Include:
  10.  
  11.     INCLUDE exec/types.i
  12.     INCLUDE    exec/memory.i
  13.     INCLUDE    exec/exec_lib.i
  14.     INCLUDE    utility/tagitem.i
  15.     INCLUDE    intuition/intuition.i
  16.     INCLUDE    intuition/intuition_lib.i
  17.     INCLUDE    intuition/screens.i
  18.     INCLUDE    graphics/graphics_lib.i
  19.     INCLUDE graphics/modeid.i
  20.     INCLUDE    graphics/rastport.i
  21.     INCLUDE    macros.i
  22.  
  23. ;*** Handler structure
  24.  
  25.  STRUCTURE vxd_handler,0
  26.   LONG intuibase
  27.   LONG graphbase
  28.   LONG myscr
  29.   LONG mywin
  30.   LONG planes
  31.   WORD xsize
  32.   WORD ysize
  33.   LONG palette
  34.   LONG palette32
  35.   LONG emuscr
  36.   WORD bytesperrow
  37.  LABEL    vxd_handler_SIZEOF
  38.  
  39.  STRUCTURE c2p,4
  40.   LONG C2PChunkyBufferAddress
  41.   LONG C2PPlanarBufferAddress
  42.   LONG C2PChunkyBufferWidth
  43.   LONG C2PChunkyBufferHeight
  44.   LONG C2PBitplaneByteWidth
  45.  LABEL c2p_SIZEOF
  46.  
  47. JSRLIB    MACRO
  48.     jsr    _LVO\1(a6)
  49.     ENDM
  50.  
  51. ;*** Let's begin
  52.  
  53.     moveq.l    #0,d0
  54.     rts
  55.  
  56.     dc.b "FLAMINGOXVD"
  57.     dc.b "1"
  58.  
  59.     dc.l Name
  60.     dc.l Author
  61.     dc.w 1
  62.     dc.w 1
  63.  
  64.     dc.l drv_Init
  65.     dc.l drv_Done
  66.     dc.l 0            ;nothing to configure
  67. ;    dc.l drv_Configure
  68.     dc.l drv_OpenScreen
  69.     dc.l drv_CloseScreen
  70.     dc.l drv_Refresh
  71.  
  72. Name:    dc.b    "AGA External Video Driver",0
  73. Author:    dc.b    "Álmos Rajnai (original C2P by Ferenc Zavacki)",0
  74.  
  75.     EVEN
  76.  
  77. ;*** Functions
  78.  
  79. drv_Init:
  80.     movem.l    a0-a1,-(sp)    ;Saving infos
  81.     move.l  4.w,a6        ;Alloc memory for handler
  82.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  83.     move.l    #vxd_handler_SIZEOF,d0
  84.     JSRLIB    AllocVec
  85.     movem.l    (sp)+,a0-a1    ;Recover infos
  86.         cmp.l    #0,d0
  87.     beq.b    .1        ;No mem
  88.     movea.l    d0,a2
  89.         move.l    (a0),graphbase(a2)    ;Saving graphics.library base
  90.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  91. .1    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  92.     rts                ;Result in D0 available for now
  93.  
  94. drv_Done:
  95.     movea.l    a0,a1
  96.     cmpa.l    #0,a1
  97.     beq.b    .1
  98.     move.l    4.w,a6
  99.     JSRLIB    FreeVec        ;Deallocate handler
  100. .1
  101.     rts
  102.  
  103. ;drv_Configure:        -> Nothing to configure
  104. ;    rts
  105.  
  106. drv_OpenScreen:
  107.     movea.l a0,a5
  108.     move.w    (a1)+,xsize(a5)
  109.     move.w    (a1)+,ysize(a5)
  110.     move.l    (a1)+,palette(a5)
  111.  
  112.     moveq.l    #0,d0
  113.     move.l    d0,d1
  114.     move.w    xsize(a5),d0
  115.     move.w    ysize(a5),d1
  116.     mulu.w    d1,d0
  117.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  118.     move.l    4.w,a6
  119.     JSRLIB    AllocVec
  120.     move.l    d0,emuscr(a5)        ;allocating emulator screen
  121.     beq.w    .1
  122.  
  123.     move.l    #MEMF_PUBLIC,d1
  124.     move.l    #128*3*4+8,d0
  125.     JSRLIB    AllocVec
  126.     move.l    d0,palette32(a5)    ;Convert palette to 32 bit per gun
  127.     beq.w    .1
  128.     movea.l    d0,a0
  129.         move.l    palette(a5),a1
  130.     move.w    #128,(a0)+
  131.     move.w    #$0,(a0)+
  132.     move.l    #128*3-1,d2
  133. .2    moveq.l    #0,d0
  134.     move.b    (a1)+,d0
  135.     swap    d0
  136.     asl.l    #8,d0
  137.     move.l    d0,(a0)+
  138.     dbf    d2,.2
  139.     move.l    #0,(a0)
  140.     move.w    xsize(a5),width+2
  141.     move.w    ysize(a5),height+2
  142.     move.l    palette32(a5),pal
  143.  
  144.         suba.l    a0,a0            ;No newscreen stuct
  145.         lea    scrtags,a1
  146.     movea.l    intuibase(a5),a6
  147.     JSRLIB    OpenScreenTagList
  148.     move.l    d0,myscr(a5)
  149.     beq.w    .1
  150.     move.l    d0,wscr
  151.     move.l    d0,a0
  152.     lea    sc_RastPort(a0),a0
  153.     movea.l    rp_BitMap(a0),a0
  154.     move.l    #BMA_FLAGS,d1
  155.     movea.l    graphbase(a5),a6
  156.     JSRLIB    GetBitMapAttr
  157.     and.l    #BMF_STANDARD|BMF_INTERLEAVED,d0
  158.     cmp.l    #BMF_STANDARD|BMF_INTERLEAVED,d0
  159.     beq.b    .3
  160.     movea.l    intuibase(a5),a6
  161.     move.l    myscr(a5),a0
  162.     JSRLIB    CloseScreen
  163.     moveq.l    #0,d0
  164.     move.l    d0,myscr(a5)
  165.     bra.b    .1
  166.  
  167. .3    move.w    xsize(a5),wwidth+2
  168.     move.w    ysize(a5),wheight+2
  169.     suba.l    a0,a0
  170.     lea    wintags,a1
  171.     movea.l    intuibase(a5),a6
  172.     JSRLIB    OpenWindowTagList
  173.     move.l    d0,mywin(a5)
  174.     beq.b    .1
  175.     movea.l    d0,a1
  176.     move.l  wd_RPort(a1),a0
  177.     move.l    rp_BitMap(a0),a0
  178.     move.l    bm_Planes(a0),planes(a5)
  179.     move.w    bm_BytesPerRow(a0),d0
  180.     and.l    #$ffff,d0
  181.     moveq.l    #7,d1
  182.     divu.w    d1,d0
  183.     move.w    d0,bytesperrow(a5)
  184.     move.l  wd_UserPort(a1),d0    ;IDCMP port
  185.     move.l    emuscr(a5),d2        ;chunky buffer
  186.  
  187. .1    move.l    #err_noscr,d1
  188.     rts
  189.  
  190. drv_CloseScreen:
  191.     move.l    a0,a5
  192.     move.l    intuibase(a5),a6
  193.     move.l    mywin(a5),a0
  194.     cmpa.l    #0,a0
  195.     beq.b    .1
  196.     JSRLIB    CloseWindow
  197.  
  198. .1    move.l    myscr(a5),a0
  199.     cmpa.l    #0,a0
  200.     beq.b    .2
  201.     JSRLIB    CloseScreen
  202.  
  203. .2    movea.l    palette32(a5),a1
  204.         cmpa.l    #0,a1
  205.     beq.b    .3
  206.     move.l    4.w,a6
  207.     JSRLIB    FreeVec        ;Deallocate translated palette
  208.  
  209. .3    movea.l    emuscr(a5),a1
  210.         cmpa.l    #0,a1
  211.     beq.b    .4
  212.     move.l    4.w,a6
  213.     JSRLIB    FreeVec        ;Deallocate translated palette
  214.  
  215. .4    moveq.l    #0,d0
  216.     move.l    d0,emuscr(a5)    ;They were already freed
  217.     move.l    d0,palette32(a5)
  218.     move.l    d0,myscr(a5)
  219.     move.l    d0,mywin(a5)
  220.  
  221.     rts
  222.  
  223. drv_Refresh:
  224.     SUBA.L    #c2p_SIZEOF,A7        ;Storing all data on stack
  225.  
  226.     MOVE.L    (emuscr,A0),(C2PChunkyBufferAddress,A7)
  227.     MOVE.L    (planes,A0),(C2PPlanarBufferAddress,A7)
  228.     MOVEQ.L    #0,D0
  229.     MOVE.W    (xsize,A0),D0
  230.     MOVE.L    D0,(C2PChunkyBufferWidth,A7)
  231.     MOVE.W    (ysize,A0),D0
  232.     MOVE.L    D0,(C2PChunkyBufferHeight,A7)
  233.     MOVE.W    (bytesperrow,A0),D0
  234.     MOVE.L    D0,(C2PBitplaneByteWidth,A7)
  235.  
  236.  
  237.         MOVE.L  (C2PChunkyBufferAddress,A7),A0
  238.         MOVE.L  (C2PChunkyBufferWidth,A7),D0
  239.         MULU.L  (C2PChunkyBufferHeight,A7),D0
  240.         LEA     (A0,D0.L),A2
  241.  
  242.         MOVE.L  (C2PPlanarBufferAddress,A7),A1
  243.  
  244.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  245.         LSR.L   #5,D6
  246.  
  247.         MOVE.L  (C2PBitplaneByteWidth,A7),D7
  248.  
  249.         MOVE.L  #$0F0F0F0F,D5
  250.  
  251.         MOVE.L  (A0)+,D0
  252.         AND.L   D5,D0
  253.         LSL.L   #4,D0
  254.         MOVE.L  (A0)+,D1
  255.         AND.L   D5,D1
  256.         OR.L    D1,D0
  257.  
  258.         MOVE.L  (A0)+,D1
  259.         AND.L   D5,D1
  260.         LSL.L   #4,D1
  261.         MOVE.L  (A0)+,D2
  262.         AND.L   D5,D2
  263.         OR.L    D2,D1
  264.  
  265.         MOVE.L  (A0)+,D2
  266.         AND.L   D5,D2
  267.         LSL.L   #4,D2
  268.         MOVE.L  (A0)+,D3
  269.         AND.L   D5,D3
  270.         OR.L    D3,D2
  271.  
  272.         MOVE.L  (A0)+,D3
  273.         AND.L   D5,D3
  274.         LSL.L   #4,D3
  275.         MOVE.L  (A0)+,D4
  276.         AND.L   D5,D4
  277.         OR.L    D4,D3
  278.  
  279.         MOVE.W  D2,D4
  280.         MOVE.W  D0,D2
  281.         SWAP    D2
  282.         MOVE.W  D2,D0
  283.         MOVE.W  D4,D2
  284.  
  285.         MOVE.W  D3,D4
  286.         MOVE.W  D1,D3
  287.         SWAP    D3
  288.         MOVE.W  D3,D1
  289.         MOVE.W  D4,D3
  290.  
  291.         MOVE.L  #$00FF00FF,D5
  292.  
  293.         MOVE.L  D1,D4
  294.         LSR.L   #8,D4
  295.         EOR.L   D0,D4
  296.         AND.L   D5,D4
  297.         EOR.L   D4,D0
  298.         LSL.L   #8,D4
  299.         EOR.L   D4,D1
  300.  
  301.         MOVE.L  D3,D4
  302.         LSR.L   #8,D4
  303.         EOR.L   D2,D4
  304.         AND.L   D5,D4
  305.         EOR.L   D4,D2
  306.         LSL.L   #8,D4
  307.         EOR.L   D4,D3
  308.  
  309.         MOVE.L  #$33333333,D5
  310.  
  311.         MOVE.L  D2,D4
  312.         LSR.L   #2,D4
  313.         EOR.L   D0,D4
  314.         AND.L   D5,D4
  315.         EOR.L   D4,D0
  316.         LSL.L   #2,D4
  317.         EOR.L   D4,D2
  318.  
  319.         MOVE.L  D3,D4
  320.         LSR.L   #2,D4
  321.         EOR.L   D1,D4
  322.         AND.L   D5,D4
  323.         EOR.L   D4,D1
  324.         LSL.L   #2,D4
  325.         EOR.L   D4,D3
  326.  
  327.         MOVE.L  #$55555555,D5
  328.  
  329.         MOVE.L  D1,D4
  330.         LSR.L   #1,D4
  331.         EOR.L   D0,D4
  332.         AND.L   D5,D4
  333.         EOR.L   D4,D0
  334.         LSL.L   #1,D4
  335.         EOR.L   D4,D1
  336.  
  337.         MOVE.L  D3,D4
  338.         LSR.L   #1,D4
  339.         EOR.L   D2,D4
  340.         AND.L   D5,D4
  341.         EOR.L   D4,D2
  342.         LSL.L   #1,D4
  343.         EOR.L   D4,D3
  344.  
  345.         MOVE.L  D0,A3
  346.         MOVE.L  D1,A4
  347.         MOVE.L  D2,A5
  348.         MOVE.L  D3,A6
  349.  
  350. .1      MOVE.L  #$0F0F0F0F,D5
  351.  
  352.         MOVE.L  (A0)+,D0
  353.         AND.L   D5,D0
  354.         LSL.L   #4,D0
  355.         MOVE.L  (A0)+,D1
  356.         AND.L   D5,D1
  357.         OR.L    D1,D0
  358.  
  359.         MOVE.L  (A0)+,D1
  360.         AND.L   D5,D1
  361.         LSL.L   #4,D1
  362.         MOVE.L  (A0)+,D2
  363.         AND.L   D5,D2
  364.         OR.L    D2,D1
  365.  
  366.         MOVE.L  (A0)+,D2
  367.         AND.L   D5,D2
  368.         LSL.L   #4,D2
  369.         MOVE.L  (A0)+,D3
  370.         AND.L   D5,D3
  371.         OR.L    D3,D2
  372.  
  373.         MOVE.L  (A0)+,D3
  374.         AND.L   D5,D3
  375.         LSL.L   #4,D3
  376.         MOVE.L  (A0)+,D4
  377.         AND.L   D5,D4
  378.         OR.L    D4,D3
  379.  
  380.         MOVE.L  A6,(A1)+
  381.  
  382.         MOVE.W  D2,D4
  383.         MOVE.W  D0,D2
  384.         SWAP    D2
  385.         MOVE.W  D2,D0
  386.         MOVE.W  D4,D2
  387.  
  388.         MOVE.W  D3,D4
  389.         MOVE.W  D1,D3
  390.         SWAP    D3
  391.         MOVE.W  D3,D1
  392.         MOVE.W  D4,D3
  393.  
  394.         MOVE.L  #$00FF00FF,D5
  395.  
  396.         MOVE.L  D1,D4
  397.         LSR.L   #8,D4
  398.         EOR.L   D0,D4
  399.         AND.L   D5,D4
  400.         EOR.L   D4,D0
  401.         LSL.L   #8,D4
  402.         EOR.L   D4,D1
  403.  
  404.         MOVE.L  A5,(-4,A1,D7.L)
  405.  
  406.         MOVE.L  D3,D4
  407.         LSR.L   #8,D4
  408.         EOR.L   D2,D4
  409.         AND.L   D5,D4
  410.         EOR.L   D4,D2
  411.         LSL.L   #8,D4
  412.         EOR.L   D4,D3
  413.  
  414.         MOVE.L  #$33333333,D5
  415.  
  416.         MOVE.L  D2,D4
  417.         LSR.L   #2,D4
  418.         EOR.L   D0,D4
  419.         AND.L   D5,D4
  420.         EOR.L   D4,D0
  421.         LSL.L   #2,D4
  422.         EOR.L   D4,D2
  423.  
  424.         MOVE.L  A4,(-4,A1,D7.L*2)
  425.  
  426.         MOVE.L  D3,D4
  427.         LSR.L   #2,D4
  428.         EOR.L   D1,D4
  429.         AND.L   D5,D4
  430.         EOR.L   D4,D1
  431.         LSL.L   #2,D4
  432.         EOR.L   D4,D3
  433.  
  434.         MOVE.L  #$55555555,D5
  435.  
  436.         MOVE.L  D1,D4
  437.         LSR.L   #1,D4
  438.         EOR.L   D0,D4
  439.         AND.L   D5,D4
  440.         EOR.L   D4,D0
  441.         LSL.L   #1,D4
  442.         EOR.L   D4,D1
  443.  
  444.         ADD.L   D7,A1
  445.         MOVE.L  A3,(-4,A1,D7.L*2)
  446.         SUB.L   D7,A1
  447.  
  448.         MOVE.L  D3,D4
  449.         LSR.L   #1,D4
  450.         EOR.L   D2,D4
  451.         AND.L   D5,D4
  452.         EOR.L   D4,D2
  453.         LSL.L   #1,D4
  454.         EOR.L   D4,D3
  455.  
  456.         MOVE.L  D0,A3
  457.         MOVE.L  D1,A4
  458.         MOVE.L  D2,A5
  459.         MOVE.L  D3,A6
  460.  
  461.         SUBQ.L   #1,D6
  462.         BNE.B   .2
  463.  
  464.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  465.         LSR.L   #3,D6
  466.         SUB.L   D6,A1
  467.         LSR.L   #2,D6
  468.         LEA     (A1,D7.L*8),A1
  469.     SUBA.L    D7,A1
  470.  
  471. .2      CMP.L   A2,A0
  472.         BNE     .1
  473.  
  474.         MOVE.L  (C2PChunkyBufferAddress,A7),A0
  475.  
  476.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  477.         LSR.L   #5,D6
  478.  
  479.         MOVE.L  #$70707070,D5
  480.  
  481.         MOVE.L  (A0)+,D0
  482.         AND.L   D5,D0
  483.         MOVE.L  (A0)+,D1
  484.         AND.L   D5,D1
  485.         LSR.L   #4,D1
  486.         OR.L    D1,D0
  487.  
  488.         MOVE.L  (A0)+,D1
  489.         AND.L   D5,D1
  490.         MOVE.L  (A0)+,D2
  491.         AND.L   D5,D2
  492.         LSR.L   #4,D2
  493.         OR.L    D2,D1
  494.  
  495.         MOVE.L  (A0)+,D2
  496.         AND.L   D5,D2
  497.         MOVE.L  (A0)+,D3
  498.         AND.L   D5,D3
  499.         LSR.L   #4,D3
  500.         OR.L    D3,D2
  501.  
  502.         MOVE.L  (A0)+,D3
  503.         AND.L   D5,D3
  504.         MOVE.L  (A0)+,D4
  505.         AND.L   D5,D4
  506.         LSR.L   #4,D4
  507.         OR.L    D4,D3
  508.  
  509.         MOVE.L  A6,(A1)+
  510.  
  511.         MOVE.W  D2,D4
  512.         MOVE.W  D0,D2
  513.         SWAP    D2
  514.         MOVE.W  D2,D0
  515.         MOVE.W  D4,D2
  516.  
  517.         MOVE.W  D3,D4
  518.         MOVE.W  D1,D3
  519.         SWAP    D3
  520.         MOVE.W  D3,D1
  521.         MOVE.W  D4,D3
  522.  
  523.         MOVE.L  #$00FF00FF,D5
  524.  
  525.         MOVE.L  D1,D4
  526.         LSR.L   #8,D4
  527.         EOR.L   D0,D4
  528.         AND.L   D5,D4
  529.         EOR.L   D4,D0
  530.         LSL.L   #8,D4
  531.         EOR.L   D4,D1
  532.  
  533.         MOVE.L  A5,(-4,A1,D7.L)
  534.  
  535.         MOVE.L  D3,D4
  536.         LSR.L   #8,D4
  537.         EOR.L   D2,D4
  538.         AND.L   D5,D4
  539.         EOR.L   D4,D2
  540.         LSL.L   #8,D4
  541.         EOR.L   D4,D3
  542.  
  543.         MOVE.L  #$33333333,D5
  544.  
  545.         MOVE.L  D2,D4
  546.         LSR.L   #2,D4
  547.         EOR.L   D0,D4
  548.         AND.L   D5,D4
  549.         EOR.L   D4,D0
  550.         LSL.L   #2,D4
  551.         EOR.L   D4,D2
  552.  
  553.         MOVE.L  A4,(-4,A1,D7.L*2)
  554.  
  555.         MOVE.L  D3,D4
  556.         LSR.L   #2,D4
  557.         EOR.L   D1,D4
  558.         AND.L   D5,D4
  559.         EOR.L   D4,D1
  560.         LSL.L   #2,D4
  561.         EOR.L   D4,D3
  562.  
  563.         MOVE.L  #$55555555,D5
  564.  
  565.         MOVE.L  D1,D4
  566.         LSR.L   #1,D4
  567.         EOR.L   D0,D4
  568.         AND.L   D5,D4
  569.         EOR.L   D4,D0
  570.         LSL.L   #1,D4
  571.         EOR.L   D4,D1
  572.  
  573.         MOVE.L  D0,A3
  574.         MOVE.L  D1,A4
  575.         MOVE.L  D2,A5
  576.         MOVE.L  D3,A6
  577.  
  578.     MOVEA.L    (C2PPlanarBufferAddress,A7),A1
  579.         LEA     (A1,D7.L*4),A1
  580.  
  581. .3      MOVE.L  #$70707070,D5
  582.  
  583.         MOVE.L  (A0)+,D0
  584.         AND.L   D5,D0
  585.         MOVE.L  (A0)+,D1
  586.         AND.L   D5,D1
  587.         LSR.L   #4,D1
  588.         OR.L    D1,D0
  589.  
  590.         MOVE.L  (A0)+,D1
  591.         AND.L   D5,D1
  592.         MOVE.L  (A0)+,D2
  593.         AND.L   D5,D2
  594.         LSR.L   #4,D2
  595.         OR.L    D2,D1
  596.  
  597.         MOVE.L  (A0)+,D2
  598.         AND.L   D5,D2
  599.         MOVE.L  (A0)+,D3
  600.         AND.L   D5,D3
  601.         LSR.L   #4,D3
  602.         OR.L    D3,D2
  603.  
  604.         MOVE.L  (A0)+,D3
  605.         AND.L   D5,D3
  606.         MOVE.L  (A0)+,D4
  607.         AND.L   D5,D4
  608.         LSR.L   #4,D4
  609.         OR.L    D4,D3
  610.  
  611.         MOVE.L  A6,(A1)+
  612.  
  613.         MOVE.W  D2,D4
  614.         MOVE.W  D0,D2
  615.         SWAP    D2
  616.         MOVE.W  D2,D0
  617.         MOVE.W  D4,D2
  618.  
  619.         MOVE.W  D3,D4
  620.         MOVE.W  D1,D3
  621.         SWAP    D3
  622.         MOVE.W  D3,D1
  623.         MOVE.W  D4,D3
  624.  
  625.         MOVE.L  #$00FF00FF,D5
  626.  
  627.         MOVE.L  D1,D4
  628.         LSR.L   #8,D4
  629.         EOR.L   D0,D4
  630.         AND.L   D5,D4
  631.         EOR.L   D4,D0
  632.         LSL.L   #8,D4
  633.         EOR.L   D4,D1
  634.  
  635.         MOVE.L  A5,(-4,A1,D7.L)
  636.  
  637.         MOVE.L  D3,D4
  638.         LSR.L   #8,D4
  639.         EOR.L   D2,D4
  640.         AND.L   D5,D4
  641.         EOR.L   D4,D2
  642.         LSL.L   #8,D4
  643.         EOR.L   D4,D3
  644.  
  645.         MOVE.L  #$33333333,D5
  646.  
  647.         MOVE.L  D2,D4
  648.         LSR.L   #2,D4
  649.         EOR.L   D0,D4
  650.         AND.L   D5,D4
  651.         EOR.L   D4,D0
  652.         LSL.L   #2,D4
  653.         EOR.L   D4,D2
  654.  
  655.         MOVE.L  A4,(-4,A1,D7.L*2)
  656.  
  657.         MOVE.L  D3,D4
  658.         LSR.L   #2,D4
  659.         EOR.L   D1,D4
  660.         AND.L   D5,D4
  661.         EOR.L   D4,D1
  662.         LSL.L   #2,D4
  663.         EOR.L   D4,D3
  664.  
  665.         MOVE.L  #$55555555,D5
  666.  
  667.         MOVE.L  D1,D4
  668.         LSR.L   #1,D4
  669.         EOR.L   D0,D4
  670.         AND.L   D5,D4
  671.         EOR.L   D4,D0
  672.         LSL.L   #1,D4
  673.         EOR.L   D4,D1
  674.  
  675.         MOVE.L  D3,D4
  676.         LSR.L   #1,D4
  677.         EOR.L   D2,D4
  678.         AND.L   D5,D4
  679.         EOR.L   D4,D2
  680.         LSL.L   #1,D4
  681.         EOR.L   D4,D3
  682.  
  683.         MOVE.L  D0,A3
  684.         MOVE.L  D1,A4
  685.         MOVE.L  D2,A5
  686.         MOVE.L  D3,A6
  687.  
  688.         SUBQ.L   #1,D6
  689.         BNE.B   .4
  690.  
  691.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  692.         LSR.L   #3,D6
  693.         SUB.L   D6,A1
  694.         LSR.L   #2,D6
  695.         LEA     (A1,D7.L*8),A1
  696.     SUBA.L    D7,A1
  697.  
  698. .4      CMP.L   A2,A0
  699.         BNE     .3
  700.  
  701.         MOVE.L  A6,(A1)+
  702.         MOVE.L  A5,(-4,A1,D7.L)
  703.         MOVE.L  A4,(-4,A1,D7.L*2)
  704.         ADD.L   D7,A1
  705.         MOVE.L  A3,(-4,A1,D7.L*2)
  706.  
  707.     MOVE.L    C2PChunkyBufferAddress(A7),D0    ;giving back chunky buffer
  708.         ADDA.L    #c2p_SIZEOF,A7
  709.     
  710.         RTS
  711.  
  712. ;*** Constants
  713.  
  714. scrtags:
  715.     dc.l    SA_Width
  716. width:    dc.l    0
  717.     dc.l    SA_Height
  718. height:    dc.l    0
  719.     dc.l    SA_Depth,7
  720.     dc.l    SA_Colors32
  721. pal:    dc.l    0
  722.     dc.l    SA_Title,scrtitle
  723.     dc.l    SA_ShowTitle,FALSE
  724.     dc.l    SA_DisplayID,LORES_KEY
  725.     dc.l    SA_Interleaved,TRUE
  726.     dc.l    SA_Type,CUSTOMSCREEN
  727.     dc.l    SA_AutoScroll,TRUE
  728.     dc.l    SA_Overscan,OSCAN_STANDARD
  729.     dc.l    SA_Quiet,TRUE
  730.     dc.l    TAG_DONE
  731.  
  732. wintags:
  733.     dc.l    WA_Left,0
  734.     dc.l    WA_Top,0
  735.     dc.l    WA_Width
  736. wwidth:    dc.l    0
  737.     dc.l    WA_Height
  738. wheight:    dc.l    0
  739.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  740.     dc.l    WA_Title,0
  741.     dc.l    WA_Backdrop,TRUE
  742.     dc.l    WA_RMBTrap,TRUE
  743.     dc.l    WA_Borderless,TRUE
  744.     dc.l    WA_NoCareRefresh,TRUE
  745.     dc.l    WA_CustomScreen
  746. wscr:    dc.l    0
  747.     dc.l    WA_SimpleRefresh,TRUE
  748.     dc.l    WA_Activate,TRUE
  749.     dc.l    TAG_DONE
  750.  
  751. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  752. ;*** Errors
  753.  
  754. err_nomem:
  755.     dc.b    'Run out of memory',0
  756. err_noscr:
  757.     dc.b    'Cannot open screen',0
  758.